// caldera.txt - A flaming caldera. If a given SDF has value 1, it is glowing. 
// If >= 2, it explodes every round 
// Does damage within 5 spaces.

// Cell 0 - Base damage it does, in d6 (changes according to difficulty)
// Cell 1,2 - Flag it's attached to
// Cell 3 - if 1, actually an acid pool. If 2, acid pool that does damage
	
beginobjectscript; // talking object

variables;

short num_fx = 6;
short last_abil;
short r1;
short boom;
short poof = 7;
short die_size = 6;

body;

beginstate INIT_STATE;
	set_object_icon(ME,7);
	set_obj_act_at_dist(ME,1);
	
	last_abil = get_current_tick();
	if (get_memory_cell(3) > 0) 
		poof = 11;
break;

beginstate DEAD_STATE;
	break;
	
beginstate START_STATE; 
	if (gf(get_memory_cell(1),get_memory_cell(2)) > 0)
		set_object_icon(ME,6);
		else set_object_icon(ME,7);
		
	boom = 0;
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_town()) && (tick_difference(last_abil,get_current_tick()) > 4))) 
		boom = 1;


	if ((gf(get_memory_cell(1),get_memory_cell(2)) >= 2) && (boom > 0)) {
		last_abil = get_current_tick();
		if (dist_to_party() <= 5) {
			die_size = 4 + 2 * difficulty();
			
			r1 = get_ran(get_memory_cell(0),1,die_size);
			if (get_memory_cell(3) == 0) {
				run_sparkles_on_object(ME,173,1,4);
				//spray_missiles(51,8,5);
	  			create_missile_spiral(154,40,5,2);
				damage_nearby(r1,5,2,0);
				}
				else {
					run_sparkles_on_object(ME,171,1,2);
					spray_missiles(52,8,5);
					status_nearby(3,5,6,0);
					if (get_memory_cell(3) == 2) 
						damage_nearby(r1,5,5,0);
					}
			play_sound(159);
			}
		}
		
	break;

beginstate RUN_ANIM_STATE;
	if ((gf(get_memory_cell(1),get_memory_cell(2)) == 1) && (get_ran(1,0,100) < 25))
		run_sparkles_on_object(ME,poof,1,1);
		
	if ((gf(get_memory_cell(1),get_memory_cell(2)) == 2) && (get_ran(1,0,100) < 75))
		run_sparkles_on_object(ME,poof,1,1);
		
		
	break;
	
beginstate USE_STATE;

break;


beginstate USE_STATE;

break;
